package com.example.a17376052_wcp_finaltest;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;

import android.view.View;
import android.view.Window;
import android.widget.ImageView;

import com.example.a17376052_wcp_finaltest.fragment.Fragment_1;
import com.example.a17376052_wcp_finaltest.fragment.Fragment_2;
import com.example.a17376052_wcp_finaltest.fragment.Fragment_3;

public class TitleActivity extends Activity implements View.OnClickListener {
    ImageView image_1, image_2, image_3;
    Fragment_1 f1;
    Fragment_2 f2;
    Fragment_3 f3;
    FragmentManager fm;
    FragmentTransaction ft;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_title);
        init();
    }

    private void init() {
        // TODO Auto-generated method stub
        image_1 = findViewById(R.id.imageView1);
        image_2 = findViewById(R.id.imageView2);
        image_3 = findViewById(R.id.imageView3);
        image_1.setOnClickListener(this);
        image_2.setOnClickListener(this);
        image_3.setOnClickListener(this);
        fm = getFragmentManager();
        ft = fm.beginTransaction();
        f1 = new Fragment_1();
        ft.replace(R.id.fragment_content, f1);
        ft.commit();
    }

    @Override
    public void onClick(View v) {
        fm = getFragmentManager();
        ft = fm.beginTransaction();
        switch (v.getId()) {
            case R.id.imageView1:
                f1 = new Fragment_1();
                ft.replace(R.id.fragment_content, f1);
                ft.commit();
                break;
            case R.id.imageView2:
                f2 = new Fragment_2();
                ft.replace(R.id.fragment_content, f2);
                ft.commit();
                break;
            case R.id.imageView3:
                f3 = new Fragment_3();
                ft.replace(R.id.fragment_content, f3);
                ft.commit();
                break;
            default:
                break;
        }
    }
}